package com.nowcoder.code.lcof;

import java.util.ArrayList;

public class JZ57 {


    public ArrayList<Integer> FindNumbersWithSum(int[] array, int sum) {

        ArrayList<Integer> list = new ArrayList<>();
        int i = 0, j = array.length - 1;

        while (i < j) {
            int s = array[i] + array[j];
            if (s == sum) {
                list.add(array[i]);
                list.add(array[j]);
                break;
            } else if (s < sum) {
                i++;
            } else {
                j--;
            }
        }
        return list;

    }
}
